package com.ncucoder.server.config;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @author <a href="https://www.ncucoder.com">hsowan</a>
 * @since 2019-01-18 12:15
 */
@Configuration
@EnableScheduling
public class TackSchedulerConfig implements SchedulingConfigurer {
    @Override
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        scheduledTaskRegistrar.setScheduler(taskScheduler());
    }

    @Bean
    public Executor taskScheduler(){
        /// return Executors.newScheduledThreadPool(100);
        return new ScheduledThreadPoolExecutor(100, new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build());
    }
}
